package com.jy.modules.cims.component.common.service;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.data.common.dao.TCMmDealInterfaceDao;
import com.jy.modules.cims.data.common.dto.TCMmDealInterfaceDTO;
import com.jy.platform.core.common.BaseDTO;

/**
 * @classname: TCMmDealInterfaceService
 * @description: 定义  T_C_MM_DEAL_INTERFACE 实现类
 * @author:  JY-IT-D001
 */
@Service("com.jy.modules.cims.component.common.service.TCMmDealInterfaceService")
public class TCMmDealInterfaceService implements Serializable {

    private static final long serialVersionUID = 1L;
    
	@Autowired
	private TCMmDealInterfaceDao dao;

	/**
     * @author JY-IT-D001
     * @description: 分页查询 T_C_MM_DEAL_INTERFACE列表
     * @date 2015-01-19 14:21:19
     * @param searchParams 条件
     * @return
     * @throws
     */ 
	public List<TCMmDealInterfaceDTO> searchTCMmDealInterfaceByPaging(Map<String,Object> searchParams) throws Exception {
		List<TCMmDealInterfaceDTO> dataList =  dao.searchTCMmDealInterfaceByPaging(searchParams);
		return dataList;
	}
	/**
     * @author JY-IT-D001
     * @description: 按条件查询T_C_MM_DEAL_INTERFACE列表
     * @date 2015-01-19 14:21:19
     * @param searchParams 条件
     * @return
     * @throws
     */
	public List<TCMmDealInterfaceDTO> searchTCMmDealInterface(Map<String,Object> searchParams) throws Exception {
	    List<TCMmDealInterfaceDTO> dataList = dao.searchTCMmDealInterface(searchParams);
        return dataList;
    }
	/**
     * @author JY-IT-D001
     * @description: 查询T_C_MM_DEAL_INTERFACE对象
     * @date 2015-01-19 14:21:19
     * @param id
     * @return
     * @throws
     */ 
	public TCMmDealInterfaceDTO queryTCMmDealInterfaceByPrimaryKey(String id) throws Exception {
		
		TCMmDealInterfaceDTO dto = dao.findTCMmDealInterfaceByPrimaryKey(id);
		
		if(dto == null) dto = new TCMmDealInterfaceDTO();
		
		return dto;
		
	}

	/**
     * @title: insertTCMmDealInterface
     * @author JY-IT-D001
     * @description: 新增 T_C_MM_DEAL_INTERFACE对象
     * @date 2015-01-19 14:21:19
     * @param dto
     * @return
     * @throws
     */
	@SuppressWarnings("all")
	public Long insertTCMmDealInterface(TCMmDealInterfaceDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		int count = dao.insertTCMmDealInterface(paramMap);
		
		TCMmDealInterfaceDTO resultDto = (TCMmDealInterfaceDTO) paramMap.get("dto");
		Long keyId = resultDto.getId();
		return keyId;
	}
	/**
	 * @Title insertTCMmDealInterface
	 * @Description TODO
	 * @param dealCode
	 * @param frontTransNo
	 * @throws Exception 
	 * void 
	 * @date 2016-11-25-上午10:20:57
	 * @update 
	 * @throws
	 */
	@Transactional(propagation=Propagation.REQUIRES_NEW, noRollbackFor=Exception.class)
	public void insertTCMmDealInterface(String dealCode, String frontTransNo) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		TCMmDealInterfaceDTO newDto = new TCMmDealInterfaceDTO();
		paramMap.put("dto", newDto);
		newDto.setDealCode(dealCode);
		newDto.setFronttransno(frontTransNo);
		newDto.setIrttime(new Timestamp(new Date().getTime()));
		newDto.setSerialno(1L);
		newDto.setStatus(CimsConstant.INTERACT_IMPL_FALSE);
		dao.insertTCMmDealInterface(paramMap);
	}
	/**
     * @title: updateTCMmDealInterface
     * @author JY-IT-D001
     * @description: 修改 T_C_MM_DEAL_INTERFACE对象
     * @date 2015-01-19 14:21:19
     * @param paramMap
     * @return
     * @throws
     */
	public void updateTCMmDealInterface(TCMmDealInterfaceDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		dao.updateTCMmDealInterface(paramMap);
	}
	/**
     * @title: deleteTCMmDealInterfaceByPrimaryKey
     * @author JY-IT-D001
     * @description: 删除 T_C_MM_DEAL_INTERFACE,按主键
     * @date 2015-01-19 14:21:19
     * @param paramMap
     * @throws
     */ 
	public void deleteTCMmDealInterfaceByPrimaryKey(BaseDTO baseDto,String ids) throws Exception {
		if(StringUtils.isEmpty(ids)) throw new Exception("删除失败！传入的参数主键为null");
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", baseDto);
		paramMap.put("ids", ids);
		dao.deleteTCMmDealInterfaceByPrimaryKey(paramMap);
	}
	

}

